home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / Advanced S22185742001.psc / frmToolbox.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-07-03  |  15.9 KB  |  501 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
  3. Begin VB.Form frmToolbox 
  4.    BorderStyle     =   4  'Fixed ToolWindow
  5.    Caption         =   "Tools"
  6.    ClientHeight    =   8415
  7.    ClientLeft      =   45
  8.    ClientTop       =   285
  9.    ClientWidth     =   1455
  10.    KeyPreview      =   -1  'True
  11.    LinkTopic       =   "Form1"
  12.    LockControls    =   -1  'True
  13.    MaxButton       =   0   'False
  14.    MDIChild        =   -1  'True
  15.    MinButton       =   0   'False
  16.    ScaleHeight     =   8415
  17.    ScaleWidth      =   1455
  18.    ShowInTaskbar   =   0   'False
  19.    Begin MSComDlg.CommonDialog CDialog 
  20.       Left            =   0
  21.       Top             =   0
  22.       _ExtentX        =   847
  23.       _ExtentY        =   847
  24.       _Version        =   393216
  25.    End
  26.    Begin VB.CommandButton cmdRandom 
  27.       Caption         =   "&Random"
  28.       Height          =   375
  29.       Left            =   75
  30.       TabIndex        =   26
  31.       Top             =   7950
  32.       Width           =   1290
  33.    End
  34.    Begin VB.Frame fmColors 
  35.       Caption         =   "Colors"
  36.       Height          =   2475
  37.       Left            =   60
  38.       TabIndex        =   17
  39.       Top             =   5400
  40.       Width           =   1335
  41.       Begin VB.OptionButton optColor 
  42.          Caption         =   "Gradient"
  43.          Height          =   255
  44.          Index           =   1
  45.          Left            =   75
  46.          TabIndex        =   23
  47.          Top             =   1575
  48.          Value           =   -1  'True
  49.          Width           =   1095
  50.       End
  51.       Begin VB.OptionButton optColor 
  52.          Caption         =   "Solid"
  53.          Height          =   255
  54.          Index           =   0
  55.          Left            =   75
  56.          TabIndex        =   20
  57.          Top             =   750
  58.          Width           =   1095
  59.       End
  60.       Begin VB.PictureBox pctBackColor 
  61.          Appearance      =   0  'Flat
  62.          BackColor       =   &H80000005&
  63.          ForeColor       =   &H80000008&
  64.          Height          =   255
  65.          Left            =   75
  66.          ScaleHeight     =   225
  67.          ScaleWidth      =   1140
  68.          TabIndex        =   19
  69.          TabStop         =   0   'False
  70.          Top             =   450
  71.          Width           =   1170
  72.       End
  73.       Begin VB.PictureBox pctGradColor 
  74.          Appearance      =   0  'Flat
  75.          BackColor       =   &H80000005&
  76.          ForeColor       =   &H80000008&
  77.          Height          =   255
  78.          Left            =   75
  79.          ScaleHeight     =   225
  80.          ScaleWidth      =   1140
  81.          TabIndex        =   25
  82.          TabStop         =   0   'False
  83.          Top             =   2100
  84.          Width           =   1170
  85.       End
  86.       Begin VB.PictureBox pctColor 
  87.          Appearance      =   0  'Flat
  88.          BackColor       =   &H80000005&
  89.          ForeColor       =   &H80000008&
  90.          Height          =   255
  91.          Left            =   75
  92.          ScaleHeight     =   225
  93.          ScaleWidth      =   1140
  94.          TabIndex        =   22
  95.          TabStop         =   0   'False
  96.          Top             =   1275
  97.          Width           =   1170
  98.       End
  99.       Begin VB.Label lblGradColor 
  100.          Caption         =   "Gradient"
  101.          Height          =   255
  102.          Left            =   75
  103.          TabIndex        =   24
  104.          Top             =   1875
  105.          Width           =   735
  106.       End
  107.       Begin VB.Label lblColor 
  108.          Caption         =   "Main"
  109.          Height          =   255
  110.          Left            =   75
  111.          TabIndex        =   21
  112.          Top             =   1050
  113.          Width           =   495
  114.       End
  115.       Begin VB.Label lblBackColor 
  116.          Caption         =   "Background"
  117.          Height          =   255
  118.          Left            =   75
  119.          TabIndex        =   18
  120.          Top             =   225
  121.          Width           =   1125
  122.       End
  123.    End
  124.    Begin VB.TextBox txtRotate 
  125.       Height          =   285
  126.       Left            =   75
  127.       TabIndex        =   16
  128.       Top             =   5025
  129.       Width           =   1290
  130.    End
  131.    Begin VB.TextBox txtZoom 
  132.       Height          =   285
  133.       Left            =   75
  134.       TabIndex        =   14
  135.       Top             =   4425
  136.       Width           =   1290
  137.    End
  138.    Begin VB.TextBox txtLineWidth 
  139.       Height          =   285
  140.       Left            =   75
  141.       TabIndex        =   12
  142.       Top             =   3825
  143.       Width           =   1290
  144.    End
  145.    Begin VB.Frame fmVectors 
  146.       Caption         =   "Vectors"
  147.       Height          =   2865
  148.       Left            =   60
  149.       TabIndex        =   2
  150.       Top             =   675
  151.       Width           =   1335
  152.       Begin VB.CommandButton cmdVectorStr 
  153.          Caption         =   "&Vector String"
  154.          Height          =   375
  155.          Left            =   75
  156.          TabIndex        =   10
  157.          Top             =   2400
  158.          Width           =   1170
  159.       End
  160.       Begin VB.TextBox txtAngle 
  161.          Enabled         =   0   'False
  162.          Height          =   285
  163.          Left            =   75
  164.          TabIndex        =   9
  165.          Top             =   2025
  166.          Width           =   1170
  167.       End
  168.       Begin VB.TextBox txtLength 
  169.          Enabled         =   0   'False
  170.          Height          =   285
  171.          Left            =   75
  172.          TabIndex        =   7
  173.          Top             =   1425
  174.          Width           =   1170
  175.       End
  176.       Begin VB.ComboBox cboVectors 
  177.          Height          =   315
  178.          Left            =   75
  179.          Style           =   2  'Dropdown List
  180.          TabIndex        =   5
  181.          Top             =   825
  182.          Width           =   1170
  183.       End
  184.       Begin VB.TextBox txtVectorCnt 
  185.          Height          =   285
  186.          Left            =   75
  187.          TabIndex        =   4
  188.          Top             =   450
  189.          Width           =   1170
  190.       End
  191.       Begin VB.Label lblAngle 
  192.          Caption         =   "Angle:"
  193.          Enabled         =   0   'False
  194.          Height          =   255
  195.          Left            =   75
  196.          TabIndex        =   8
  197.          Top             =   1800
  198.          Width           =   855
  199.       End
  200.       Begin VB.Label lblLength 
  201.          Caption         =   "Length:"
  202.          Enabled         =   0   'False
  203.          Height          =   255
  204.          Left            =   75
  205.          TabIndex        =   6
  206.          Top             =   1200
  207.          Width           =   855
  208.       End
  209.       Begin VB.Label lblVectors 
  210.          AutoSize        =   -1  'True
  211.          Caption         =   "Vector Count"
  212.          Height          =   195
  213.          Left            =   75
  214.          TabIndex        =   3
  215.          Top             =   225
  216.          Width           =   930
  217.       End
  218.    End
  219.    Begin VB.CheckBox chkGrid 
  220.       Caption         =   "Grid"
  221.       Height          =   255
  222.       Left            =   75
  223.       TabIndex        =   1
  224.       Top             =   375
  225.       Width           =   1290
  226.    End
  227.    Begin VB.CheckBox chkAxis 
  228.       Caption         =   "X/Y Axis"
  229.       Height          =   255
  230.       Left            =   75
  231.       TabIndex        =   0
  232.       Top             =   75
  233.       Width           =   1290
  234.    End
  235.    Begin VB.Label lblRotate 
  236.       AutoSize        =   -1  'True
  237.       Caption         =   "Rotate:"
  238.       Height          =   195
  239.       Left            =   75
  240.       TabIndex        =   15
  241.       Top             =   4800
  242.       Width           =   525
  243.    End
  244.    Begin VB.Label lblZoom 
  245.       AutoSize        =   -1  'True
  246.       Caption         =   "Zoom:"
  247.       Height          =   195
  248.       Left            =   75
  249.       TabIndex        =   13
  250.       Top             =   4200
  251.       Width           =   450
  252.    End
  253.    Begin VB.Label lblLineWidth 
  254.       AutoSize        =   -1  'True
  255.       Caption         =   "Line Width:"
  256.       Height          =   195
  257.       Left            =   75
  258.       TabIndex        =   11
  259.       Top             =   3600
  260.       Width           =   810
  261.    End
  262. Attribute VB_Name = "frmToolbox"
  263. Attribute VB_GlobalNameSpace = False
  264. Attribute VB_Creatable = False
  265. Attribute VB_PredeclaredId = True
  266. Attribute VB_Exposed = False
  267. ' frmToolbox
  268. ' This form allows the user to alter the properties of a selected
  269. ' shape.
  270. Option Explicit
  271. ' Enable/Disable all controls on the toolbox
  272. Public Sub Activate(Optional Enabled As Boolean = True)
  273. Dim i As Integer
  274.     On Error Resume Next
  275.     For i = 0 To Controls.Count
  276.         Controls(i).Enabled = Enabled
  277.     Next i
  278. End Sub
  279. ' Display information on the selected vector.
  280. Private Sub cboVectors_Click()
  281. Dim Length As Double, Angle As Double
  282.     SelWindow.Gadget.GetVector cboVectors.ListIndex + 1, Length, Angle
  283.     txtLength = Length
  284.     txtAngle = Angle & "
  285. End Sub
  286. Private Sub chkAxis_Click()
  287.     SelWindow.ShowAxis = chkAxis.Value
  288. End Sub
  289. Private Sub chkGrid_Click()
  290.     SelWindow.ShowGrid = chkGrid.Value
  291. End Sub
  292. Function IsNothing(TestObj As Object) As Boolean
  293.     On Error Resume Next
  294.     ' Returns True if error
  295.     If TestObj.Name = "" Then IsNothing = True
  296. End Function
  297. ' Creates random shape and colors
  298. Private Sub cmdRandom_Click()
  299. Dim i As Integer
  300.     Randomize Timer
  301.     With SelWindow
  302.         With .Gadget
  303.             .ClearVectors
  304.             .SetVectorCnt (Int(Rnd * 10) + 1)
  305.             For i = 1 To .VectorCnt
  306.                 .SetVector i, Int(Rnd * 60) + 5, Int(Rnd * 360)
  307.             Next i
  308.         End With
  309.         .GradColor = RGB(Int(Rnd * 156) + 100, Int(Rnd * 156) + 100, Int(Rnd * 156) + 100)
  310.         .BaseColor = RGB(Int(Rnd * 156) + 100, Int(Rnd * 156) + 100, Int(Rnd * 156) + 100)
  311.     End With
  312.     GetSettings
  313. End Sub
  314. ' Prompt for vector code.
  315. Private Sub cmdVectorStr_Click()
  316. Dim RetStr As String
  317.     RetStr = InputBox("Type in your vector code here. Separate vectors by colons ("":""), and separate lengths from angles with a less-than sign (""<"").", , SelWindow.Gadget.CreateVectorStr)
  318.     If RetStr = vbNullString Then Exit Sub
  319.     SelWindow.Gadget.TakeVectorStr RetStr
  320.     LoadVectors
  321. End Sub
  322. Private Sub Form_Load()
  323.     frmMDI.ChangeToolBoxState True
  324.     ' If no window is open, deactivate toolbox.
  325.     If IsNothing(SelWindow) Then
  326.         Activate False
  327.     Else
  328.         GetSettings
  329.     End If
  330. End Sub
  331. Private Sub Form_Unload(Cancel As Integer)
  332.     frmMDI.ChangeToolBoxState False
  333. End Sub
  334. Private Sub optColor_Click(Index As Integer)
  335. Dim GradMode As Boolean
  336.     GradMode = (Index = 1)
  337.     SelWindow.Gradient = GradMode
  338.     pctGradColor.Enabled = GradMode
  339.     lblGradColor.Enabled = GradMode
  340. End Sub
  341. ' Load all the shape's vectors to the cboVectors dropdown list.
  342. Sub LoadVectors()
  343. Dim i As Integer, OldIdx As Integer
  344.     On Error Resume Next
  345.     OldIdx = cboVectors.ListIndex
  346.     If OldIdx = -1 Then OldIdx = 0
  347.     cboVectors.Clear
  348.     txtVectorCnt = SelWindow.Gadget.VectorCnt
  349.     For i = 1 To SelWindow.Gadget.VectorCnt
  350.         cboVectors.AddItem i
  351.     Next i
  352.     If cboVectors.ListIndex = -1 Then cboVectors.ListIndex = 0
  353.     If cboVectors.ListCount > OldIdx Then cboVectors.ListIndex = OldIdx
  354. End Sub
  355. ' Check a textbox if it is numeric and in bounds
  356. Function Validate(StrVal As String, Min As Double, Max As Double) As Boolean
  357. Const IGNORE = "%
  358.     StrVal = Trim$(StrVal)
  359.     If InStr(1, IGNORE, Right(StrVal, 1)) > 0 Then StrVal = Left(StrVal, Len(StrVal) - 1)
  360.     Validate = IsNumeric(StrVal) And Val(StrVal) >= Min And Val(StrVal) <= Max
  361. End Function
  362. Public Sub GetSettings()
  363.     ' Load all the settings from the selected instance of frmTest
  364.     With SelWindow
  365.         chkGrid.Value = -.ShowGrid
  366.         chkAxis.Value = -.ShowAxis
  367.         LoadVectors
  368.         txtLineWidth = .LineWidth
  369.         txtZoom = .Gadget.Zoom & "%"
  370.         txtRotate = .Gadget.Rotate & "
  371.         optColor(Abs(.Gradient)).Value = True
  372.         pctBackColor.BackColor = .BkColor
  373.         pctColor.BackColor = .BaseColor
  374.         pctGradColor.BackColor = .GradColor
  375.     End With
  376. End Sub
  377. Private Sub pctBackColor_Click()
  378.     ShowColors pctBackColor
  379.     SelWindow.BkColor = pctBackColor.BackColor
  380. End Sub
  381. Private Sub pctColor_Click()
  382.     ShowColors pctColor
  383.     SelWindow.BaseColor = pctColor.BackColor
  384. End Sub
  385. ' Prompts a color dialog box for a selected PictureBox control.
  386. Sub ShowColors(PBox As PictureBox)
  387.     CDialog.Color = PBox.BackColor
  388.     CDialog.ShowColor
  389.     PBox.BackColor = CDialog.Color
  390. End Sub
  391. Private Sub pctGradColor_Click()
  392.     ShowColors pctGradColor
  393.     SelWindow.GradColor = pctGradColor.BackColor
  394. End Sub
  395. Private Sub txtAngle_Change()
  396. Dim ValidNum As Boolean
  397.     On Error Resume Next
  398.     If cboVectors.ListIndex = -1 Then Exit Sub
  399.     ValidNum = Validate(txtAngle, 0, 32766)
  400.     txtAngle.ForeColor = 255 * (ValidNum + 1)
  401.     If Not ValidNum Then Exit Sub
  402.     SelWindow.Gadget.SetVector cboVectors.ListIndex + 1, txtLength, Val(txtAngle)
  403. End Sub
  404. Private Sub txtAngle_GotFocus()
  405.     SetTBoxFocus txtAngle
  406. End Sub
  407. Private Sub txtAngle_KeyPress(KeyAscii As Integer)
  408.     If cboVectors.ListIndex = -1 Then Beep: KeyAscii = 0
  409. End Sub
  410. Private Sub txtAngle_LostFocus()
  411.     FixAngle txtAngle
  412. End Sub
  413. Private Sub txtLength_Change()
  414. Dim ValidNum As Boolean
  415.     ValidNum = Validate(txtLength, 0, 32766)
  416.     txtLength.ForeColor = 255 * (ValidNum + 1)
  417.     If Not ValidNum Then Exit Sub
  418.     SelWindow.Gadget.SetVector cboVectors.ListIndex + 1, Val(txtLength), Val(txtAngle)
  419. End Sub
  420. Private Sub txtLength_GotFocus()
  421.     SetTBoxFocus txtLength
  422. End Sub
  423. Private Sub txtLength_KeyPress(KeyAscii As Integer)
  424.     If cboVectors.ListIndex = -1 Then Beep: KeyAscii = 0
  425. End Sub
  426. Private Sub txtLineWidth_Change()
  427. Dim ValidNum As Boolean
  428.     ValidNum = Validate(txtLineWidth, 0, 32766)
  429.     txtLineWidth.ForeColor = 255 * (ValidNum + 1)
  430.     If Not ValidNum Then Exit Sub
  431.     If Not Validate(txtLineWidth, 1, 60) Then Exit Sub
  432.     SelWindow.LineWidth = txtLineWidth
  433. End Sub
  434. Private Sub txtLineWidth_GotFocus()
  435.     SetTBoxFocus txtLineWidth
  436. End Sub
  437. Private Sub txtRotate_GotFocus()
  438.     SetTBoxFocus txtRotate
  439. End Sub
  440. Private Sub txtRotate_LostFocus()
  441.     FixAngle txtRotate
  442. End Sub
  443. Private Sub txtVectorCnt_Change()
  444. Dim ValidNum As Boolean
  445.     ValidNum = Validate(txtVectorCnt, 0, 1000)
  446.     txtVectorCnt.ForeColor = 255 * (ValidNum + 1)
  447. End Sub
  448. Private Sub txtVectorCnt_GotFocus()
  449.     SetTBoxFocus txtVectorCnt
  450. End Sub
  451. Private Sub txtZoom_Change()
  452. Dim ValidNum As Boolean, txtStr As String, i As Integer
  453.     If txtZoom = "" Then Exit Sub
  454.     i = InStr(1, txtZoom, "%")
  455.     If i = 0 Then i = Len(txtZoom) + 1
  456.     txtStr = Left(txtZoom, i - 1)
  457.     ValidNum = Validate(txtStr, 0, 32766)
  458.     txtZoom.ForeColor = 255 * (ValidNum + 1)
  459.     If Not ValidNum Then Exit Sub
  460.     SelWindow.Gadget.Zoom = Val(txtZoom)
  461. End Sub
  462. ' Fix an angle so that it is from 0 to 359
  463. Sub FixAngle(ByRef TBox As TextBox)
  464. Dim Step As Integer, TNum As Integer
  465.     On Error Resume Next
  466.     TNum = Val(TBox)
  467.     If Val(TNum) > 0 Then
  468.         Step = -Abs(TNum) / TNum
  469.         Do While TNum >= 360 Or TNum < 0
  470.             TNum = TNum + Step * 360
  471.         Loop
  472.     End If
  473.     TBox = TNum & "
  474. End Sub
  475. Private Sub txtRotate_Change()
  476. Dim ValidNum As Boolean
  477.     ValidNum = Validate(txtRotate, 0, 32766)
  478.     txtRotate.ForeColor = 255 * (ValidNum + 1)
  479.     If Not ValidNum Then Exit Sub
  480.     SelWindow.Gadget.Rotate = Val(txtRotate)
  481. End Sub
  482. Private Sub SetTBoxFocus(TBox As TextBox)
  483.     TBox.SelStart = 0
  484.     TBox.SelLength = Len(TBox)
  485. End Sub
  486. Private Sub txtVectorCnt_LostFocus()
  487.     If Not Validate(txtVectorCnt, 0, 1000) Then Exit Sub
  488.     'txtAngle.Enabled = txtVectorCnt > 0
  489.     'txtLength.Enabled = txtVectorCnt > 0
  490.     SelWindow.Gadget.SetVectorCnt txtVectorCnt
  491.     LoadVectors
  492. End Sub
  493. Private Sub txtZoom_GotFocus()
  494.     SetTBoxFocus txtZoom
  495. End Sub
  496. Private Sub txtZoom_LostFocus()
  497.     On Error Resume Next
  498.     ' Add a percent sign onto txtZoom
  499.     txtZoom = Val(txtZoom) & "%"
  500. End Sub
  501.